<template>
  <el-dialog width="70%" :visible.sync="this.HlryDialog > 0" :close-on-click-modal="false" :before-close="qyryCancel" append-to-body>
    <div class="app-container">
      <!--工具栏-->
      <div class="head-container">
        <div>
          <!-- 搜索 -->
          <el-input v-model="query.blurry" clearable size="small" placeholder="模糊搜索" style="width: 200px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
          <rrOperation />
        </div>
      </div>
      <!--表格渲染-->
      <el-table
        ref="dspQyryTable"
        v-loading="crud.loading"
        :data="crud.data"
        size="small"
        style="width: 100%;"
        @selection-change="crud.selectionChangeHandler"
      >
        <el-table-column type="selection" width="55" />
        <el-table-column prop="bisRyglXm" label="姓名" />
        <el-table-column prop="bisRyglXb" label="性别">
          <template slot-scope="scope">
            {{ dict.label.xb[scope.row.bisRyglXb] }}
          </template>
        </el-table-column>
        <el-table-column prop="bisRyglLxdh" label="联系电话" />
        <el-table-column prop="bisRyglZjhm" label="身份证" />
        <el-table-column prop="bisRyglRylb" label="人员类别">
          <template slot-scope="scope">
            {{ dict.label.hlrylx[scope.row.bisRyglRylb] }}
          </template>
        </el-table-column>
      </el-table>
      <!--分页组件-->
      <pagination />
    </div>
    <div slot="footer" class="dialog-footer">
      <el-button @click="qyryCancel">取消</el-button>
      <el-button :loading="this.HlryDialog === 2" type="primary" @click="qyrySubmit">确认</el-button>
    </div>
  </el-dialog>
</template>

<script>
import crudQyry from '@/api/business/qyry'
import crudFpry from '@/api/business/fpry'
import CRUD, { presenter, header, form, crud } from '@crud/crud'
import rrOperation from '@crud/RR.operation'
import crudOperation from '@crud/CRUD.operation'
import udOperation from '@crud/UD.operation'
import pagination from '@crud/Pagination'

const defaultForm = { bisRyglId: null, bisRyglUserId: null, bisPggsId: null, bisRyglXm: null, bisRyglXb: null, bisRyglLxdh: null, bisRyglZjlx: '居民身份证', bisRyglZjhm: null, bisRyglJj: null, bisRyglYbqh: null, bisRyglYhdl: null, bisRyglKhhmc: null, bisRyglKhhid: null, bisRyglYhzh: null, bisRyglYhhm: null, bisRyglZjlb: null, bisRyglZjjszc: null, bisRyglXrzw: null, bisRyglZjks: null, bisRyglYzbm: null, bisRyglDzyx: null }
export default {
  name: 'Pgry',
  // eslint-disable-next-line vue/no-unused-components
  components: { pagination, crudOperation, rrOperation, udOperation },
  mixins: [presenter(), header(), form(defaultForm), crud()],
  dicts: ['xb', 'rylx', 'hlrylx', 'zjlx'],
  cruds() {
    return CRUD({ title: '评估人员', url: 'api/hlry', idField: 'bisRyglId', sort: 'bisRyglId,desc', crudMethod: { ...crudQyry, crudFpry }})
  },
  data() {
    return {
      zjlx: '01',
      HlryDialog: 0,
      selectedZhids: [],
      selectedHlrys: [],
      submitProcessing: false,
      permission: {
        add: ['admin', 'pgry:add'],
        edit: ['admin', 'pgry:edit'],
        del: ['admin', 'pgry:del']
      },
      rules: {
        bisRyglXm: [
          { required: true, message: '姓名不能为空', trigger: 'blur' }
        ],
        bisRyglXb: [
          { required: true, message: '性别不能为空', trigger: 'blur' }
        ],
        bisRyglLxdh: [
          { required: true, message: '联系电话不能为空', trigger: 'blur' }
        ],
        bisRyglZjhm: [
          { required: true, message: '证件号码不能为空', trigger: 'blur' }
        ],
        bisRyglZjlb: [
          { required: true, message: '专家类别不能为空', trigger: 'blur' }
        ]
      },
      queryTypeOptions: [
        { key: 'bisRyglXm', display_name: '姓名' },
        { key: 'bisRyglXb', display_name: '性别' },
        { key: 'bisRyglLxdh', display_name: '联系电话' },
        { key: 'bisRyglZjhm', display_name: '证件号码' },
        { key: 'bisRyglZjlb', display_name: '专家类别' }
      ]
    }
  },
  created() {
    this.form.bisRyglZjlx = this.zjlx
    this.form.bisRyglZjhm = this.zjlx
    console.log(this.form.bisRyglZjlx)
  },
  methods: {
    qyryCancel() {
      this.HlryDialog = 0
    },
    qyrySubmit() {
      this.selectedHlrys = []
      this.crud.selections.forEach((item, index) => {
        this.selectedHlrys.push(item.bisRyglUserId)
      })
      if (this.selectedHlrys.length === 0) {
        this.$notify({
          title: '请选择护理人员',
          type: 'warning',
          duration: 2500
        })
        return
      }
      this.HlryDialog = 2
      const params = {
        'selectedZhids': this.selectedZhids,
        'selectedPgrys': this.selectedHlrys,
        'ywlx': 'hl'
      }
      crudFpry.createFpry(params).then(() => {
        this.crud.notify('保存成功', CRUD.NOTIFICATION_TYPE.SUCCESS)
        this.$refs.dspQyryTable.clearSelection()
        this.HlryDialog = 0
        this.$emit('doQuery')
      }).catch(err => {
        console.log(err.response.data.message)
      })
    },
    // 钩子：在获取表格数据之前执行，false 则代表不获取数据
    [CRUD.HOOK.beforeRefresh]() {
      return true
    }
  }
}
</script>

<style scoped>

</style>
